package com.atos.smp.dao.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; 
import com.atos.smp.beans.Process;
import com.atos.smp.beans.Rule;

import org.hibernate.criterion.Example;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.atos.smp.beans.Collaborator;
import com.atos.smp.dao.CollaboratorDao;

public class CollaboratorDaoImpl extends HibernateDaoSupport implements CollaboratorDao,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Collaborator> collaborators;
	
	public CollaboratorDaoImpl() {
		collaborators = new ArrayList<Collaborator>();
		
	}
	@Override
	public void save(Collaborator collaborator) {
		getHibernateTemplate().persist(collaborator);
	}

	@Override
	public void update(Collaborator collaborator) {
		getHibernateTemplate().update(collaborator);
	}

	@Override
	public void delete(Collaborator collaborator) {
		getHibernateTemplate().delete(collaborator);
	}

	@Override
	public Collaborator findCollaboratorByDas(String das) {
		
		@SuppressWarnings("unchecked")
		List<Collaborator> list = getHibernateTemplate().find("from Collaborator where das='"+das+"'");
		if(list != null &&  list.size()>0){
			return (Collaborator) list.get(0);
		}
		
		else
			return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Collaborator> findAllCollaborators() {
		collaborators = getHibernateTemplate().find("from Collaborator");
		return collaborators;
	}
	@Override
	public List<Process> findAllProcess() {
		
		return null;
	}
	
	public List<Process> findProcessByDate(Date date) {
		
		return null;
	}
	
	
	public List<Process> findProcessByName(String name) {
		List<Process> processes = getHibernateTemplate().find("from Process where name="+name);
		return processes;
		
	}
	@Override
	public List<Collaborator> findAllManagers() {
		Collaborator c = new Collaborator();
		c.setRule(Rule.Manager);
		List<Collaborator> managers = getHibernateTemplate().findByExample(c);
		return managers;
	}
	@Override
	public List<Collaborator> findAllProjectManagers() {
		Collaborator c = new Collaborator();
		c.setRule(Rule.Project_Manager);
		List<Collaborator> pManagers = getHibernateTemplate().findByExample(c);
		return pManagers;
	}
	
	

    
}
